package user

import (
	"context"
	"go.uber.org/zap"
	"srv/config"
	"srv/internal/model/dao"
	__ "srv/proto"
)

// 定义空接口
type UserService struct {
	__.UnimplementedUseServiceServer
}

// 实现方法
func (s *UserService) UserLogin(ctx context.Context, req *__.UserLoginRequest) (resp *__.UserLoginResponse, err error) {
	var user dao.User
	config.DB.Where("mobile=?", req.Mobile).Limit(1).Find(&user)
	if user.ID == 0 {
		zap.S().Error("该用户不存在")
		return
	}
	get := config.Rdb.Get(req.Mobile)
	if get.Val() != req.Number {
		zap.S().Error("验证码不正确")
		return
	}
	if user.Password != req.Password {
		zap.S().Error("密码错误")
		return
	}
	return &__.UserLoginResponse{Id: int64(user.ID)}, nil
}
